import requests,logging
class Testcase():
    uid=None
    sid=None
    addid=None
    ordid=None
    def setup_method(self):
        print("开始")
    def teardown_method(self):
        print("退出")
    # 登录
    def test_001(self):
        try:
            url="http://10.59.9.18/small/user/v1/login"
            headers=None
            data={"phone":"13811033965","pwd":"123456Aa"}
            r=requests.post(url=url,json=data)
            print("登录：",r.json())
            assert r.json()["message"]=="登录成功"
            Testcase.uid=str(r.json()["result"]["userId"])
            Testcase.sid=r.json()["result"]["sessionId"]
        except Exception as e:
            logging.info(e)
    # 首页商品详情
    def test_002(self):
        try:
            url="http://10.59.9.18/small/commodity/v1/commodityList"
            headers=None
            data=None
            r=requests.get(url=url)
            print("首页商品详情：",r.json())
            assert r.json()["message"] == "查询成功"
        except Exception as e:
            logging.info(e)
    # 商品详情
    def test_003(self):
        try:
            url="http://10.59.9.18/small/commodity/v1/findCommodityDetailsById"
            headers={"userId":Testcase.uid,"sessionId":Testcase.sid}
            data={"commodityId":23}
            r=requests.get(url=url,headers=headers,params=data)
            print("商品详情：",r.json())
            assert r.status_code==200
            Testcase.addid=r.json()["result"]["categoryId"]
        except Exception as e:
            logging.info(e)
    # 查看收货地址
    def test_004(self):
        try:
            url="http://10.59.9.18/small/user/verify/v1/receiveAddressList"
            headers={"userId":Testcase.uid,"sessionId":Testcase.sid}
            data=None
            r=requests.get(url=url,headers=headers)
            print("收货地址：",r.json())
            assert r.status_code==200
        except Exception as e:
            logging.info(e)
    # 创建订单
    def test_005(self):
        try:
            url="http://10.59.9.18/small/order/verify/v1/createOrder"
            headers={"userId":Testcase.uid,"sessionId":Testcase.sid}
            data={"orderInfo":'[{"commodityId":23,"amount":1}]',"totalPrice":139,"addressId":2878}
            r=requests.post(url=url,headers=headers,params=data)
            print("创建订单：",r.json())
            assert r.status_code==200
            Testcase.ordid=r.json()["orderId"]
        except Exception as e:
            logging.info(e)
    # 支付
    def test_006(self):
        try:
            url="http://10.59.9.18/small/order/verify/v1/pay"
            headers={"userId":Testcase.uid,"sessionId":Testcase.sid}
            data={"orderId":Testcase.ordid,"payType":1}
            r=requests.post(url=url,headers=headers,params=data)
            print("支付：",r.json())
            assert r.status_code==200
        except Exception as e:
            logging.info(e)
    # 收货
    def test_007(self):
        try:
            url="http://10.59.9.18/small/order/verify/v1/confirmReceipt"
            headers={"userId":Testcase.uid,"sessionId":Testcase.sid}
            data={"orderId":Testcase.ordid}
            r=requests.put(url=url,headers=headers,params=data)
            print("支付：",r.json())
            assert r.status_code==200
        except Exception as e:
            logging.info(e)
    # 商品评论
    def test_008(self):
        try:
            url="http://10.59.9.18/small/commodity/verify/v1/addCommodityComment"
            headers={"userId":Testcase.uid,"sessionId":Testcase.sid}
            data={"commodityId":23,"orderId":Testcase.ordid,
                  "content":"不错","image":"111.png"}
            r=requests.post(url=url,headers=headers,params=data)
            print("商品评论：",r.json())
            assert r.status_code==200
        except Exception as e:
            logging.info(e)